package com.yjhb.android.sbz.dialog;

import android.app.Dialog;
import android.content.Context;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.view.checkbox.SmoothCheckBox;

/**
 * 创建者 zx
 * 创建时间 2020/11/25 14:32
 */
public class TipsDialog extends Dialog implements View.OnClickListener, SmoothCheckBox.OnCheckedChangeListener {
    private final String TAG = "TipsDialog";
    protected TextView title_tv;
    protected TextView content_tv;
    protected TextView cancel_tv;
    protected TextView submit_tv;
    protected LinearLayout cancel;
    protected LinearLayout submit;
    protected LinearLayout notips;
    protected SmoothCheckBox checkbox;
    OnClickListener clickListener;
    public static final int TYPE_CANCEL = 1;
    public static final int TYPE_SUBMIT = 2;
    public static final int TYPE_CHECK = 3;

    public TipsDialog(@NonNull Context context) {
        super(context, R.style.mDialog);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_tips, null, false);
        title_tv = view.findViewById(R.id.title_tv);
        content_tv = view.findViewById(R.id.content_tv);
        cancel = view.findViewById(R.id.cancel);
        submit = view.findViewById(R.id.submit);
        cancel_tv = view.findViewById(R.id.cancel_tv);
        submit_tv = view.findViewById(R.id.submit_tv);
        notips = view.findViewById(R.id.notips);
        checkbox = view.findViewById(R.id.checkbox);
        setContentView(view);
        setCancelable(true);
        setCanceledOnTouchOutside(false);
        cancel_tv.setOnClickListener(this);
        submit_tv.setOnClickListener(this);
        checkbox.setOnCheckedChangeListener(this);
    }

    public void setButtonVisibility(int button, int visibility) {
        if (TYPE_CANCEL == button) {
            cancel.setVisibility(visibility);
        } else if (TYPE_SUBMIT == button) {
            submit.setVisibility(visibility);
        } else if (TYPE_CHECK == button) {
            notips.setVisibility(visibility);
        }
    }

    public void setTitle(CharSequence title) {
        title_tv.setText(title);
    }

    public void setContent(CharSequence content) {
        content_tv.setText(content);
    }

    public void setCancelText(CharSequence cancelText) {
        cancel_tv.setText(cancelText);
    }

    public void setSubmitText(CharSequence submitText) {
        submit_tv.setText(submitText);
    }

    public void setCancelColor(@ColorInt int color) {
        cancel_tv.setTextColor(color);
    }

    public void setSubmitColor(@ColorInt int color) {
        submit_tv.setTextColor(color);
    }

    public TextView getContentTextView() {
        return content_tv;
    }

    public TextView getSubmitTextView() {
        return submit_tv;
    }

    public TextView getCancelTextView() {
        return cancel_tv;
    }

    public SmoothCheckBox getCheckbox(){
        return checkbox;
    }

    public void setOnClickListener(OnClickListener clickListener) {
        this.clickListener = clickListener;
    }

    public void setContentGravity(int gravity) {
        content_tv.setGravity(gravity);
    }

    @Override
    public void onClick(View v) {
        if (v == cancel_tv) {
            if (clickListener != null) {
                clickListener.onClick(TYPE_CANCEL);
            }
        } else if (v == submit_tv) {
            if (clickListener != null) {
                clickListener.onClick(TYPE_SUBMIT);
            }
        }

    }

    @Override
    public void onCheckedChanged(SmoothCheckBox checkBox, boolean isChecked) {

    }

    public interface OnClickListener {
        void onClick(int type);
    }


}
